package exec.exec4;

import java.util.Scanner;

public class DivisionDemo {
    public static void main(String[] args) {

        try {
            int a = Integer.parseInt(args[0]);
            int b = Integer.parseInt(args[1]);// ArrayIndexOutOfBoundsException NumberFormatException

            int result = divide(a, b);// BelowZeroException ArithmeticException
            System.out.println(result);

        } catch (BelowZeroException e) {//这里 BelowZeroException 是编译时异常 下面的三种是运行时异常，实际情况不需要catch ！！！
            System.out.println(e.getMessage());
        } catch (NumberFormatException e){
            System.out.println("数据类型不一致！");
        } catch (ArithmeticException e){
            System.out.println("分母不能为0");
        } catch (ArrayIndexOutOfBoundsException e){
            System.out.println("缺少命令行参数");
        }

    }
    public static int divide(int a, int b) throws BelowZeroException {
        if (a < 0 || b < 0) {
            throw new BelowZeroException("数值小于零 "+a+" "+b);
        }
        return a / b;
    }
}
